<script src="../js/jquery.validationEngine.js" type="text/javascript"></script>
<link rel="stylesheet" href="../css/validationEngine.jquery.css" type="text/css" media="screen" title="no title" charset="utf-8" />
<script>
$(function() {
	$("[class^=validate]").validationEngine({
		success : function() { 
		 $('form').submit();
		 }, 
		failure : function() {return false;}
	});
});
</script>
<?php
$prefix = 'admin';
if($_POST['action']=='save')
{
	$data = array(
		'username'=>$_POST['username'],
		'password'=>$_POST['password'],
		'email'=>$_POST['email']
	);	
	if($_POST['id']){
		update("tb_$prefix",$data,"id = '".$_POST['id']."'");
		$id = $_POST['id'];
	}else{
		insert("tb_$prefix",$data);	
		$id = mysql_insert_id();	
	}
	echo "<script>window.location='admin.php?page=user'</script>";
}
$sql = "select * from tb_$prefix where id = '".$_GET['id']."'";
$qr = select($sql);
$rs = $qr[0];
?>
<div id="dialog_active" title="ข้อความ"  style="display:none;">
	<p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span>ต้องการเปลี่ยนสถานะ?</p>
</div>
<div id="dialog2" title="ข้อความ"  style="display:none;">
	<p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span>ต้องการลบข้อมูล?</p>
</div>
<div id="member_dialog" title="ข้อมูลสมาชิก"  style="display:none;"></div>
<div id="tabs">
    <ul>
    	<li><a class="head_tab" style="padding-left:7px;" href="#tabs-1"><span class="ui-icon ui-icon-person" style="float:left;"></span>User</a></li>
    </ul>
    <div id="tabs-1">
    	<form action="" method="post" enctype="multipart/form-data" id="content-form">
          <table width="100%" border="0" cellspacing="0" cellpadding="5">
                  <tr>
                    <td width="8%"><strong>Username</strong></td>
                    <td width="92%">
                    <input type="text" name="username" id="username" value="<?=$rs['username']?>"  class="validate[required,custom[noSpecialCaracters],length[0,20]]" /></td>
                </tr>
                  <tr>
                    <td valign="top"><strong>Password</strong></td>
                    <td>
                    <input class="validate[required,length[6,11]]" type="password" name="password" id="password" value="<?=$rs['password']?>" /></td>
                </tr>
                  <tr>
                    <td valign="top"><strong>Confirm Password</strong></td>
                    <td>
                    <input class="validate[required,confirm[password]]" type="password" name="repass" id="repass" value="<?=$rs['password']?>" /></td>
                  </tr>
                  <tr>
                    <td><strong>Email</strong></td>
                    <td><label for="email"></label>
                    <input type="text" name="email" id="email" value="<?=$rs['email']?>" class="validate[required,custom[email]]" /></td>
                  </tr>
                  <tr>
                    <td>&nbsp;</td>
                    <td><input type="submit" name="button" id="button" value="Submit" />
                    <input name="id" type="hidden" id="id" value="<?=$rs['id']?>" />
                    <input name="action" type="hidden" id="action" value="save" /></td>
                  </tr>
          </table>
      </form>
    </div>
</div>            